import axios from 'axios'
// import { message } from './resetMessage'
import { ElMessage } from 'element-plus'
import { getEnv } from './env'
const { VITE_APP_BASE_API } = getEnv()
const service = axios.create({
    baseURL: VITE_APP_BASE_API,
    timeout: 10000,
})

service.interceptors.request.use(
    (config) => {
        // 在发送请求之前做些什么
        return config
    },
    (error) => {
        // 对请求错误做些什么
        ElMessage.error('请求发送失败，请检查网络或重试')
        return Promise.reject(error)
    }
)

service.interceptors.response.use(
    (response) => {
        return response.data.payload || response.data
    },
    (error) => {
        return Promise.reject(error)
    }
)

export default service
